package com.sws.web.controller.student_attendance.attendance;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;

import com.sws.capture.service.CapRecordService;
import com.sws.person.service.IPerPersonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.sws.common.annotation.Log;
import com.sws.common.core.controller.BaseController;
import com.sws.common.core.domain.AjaxResult;
import com.sws.common.enums.BusinessType;
import com.sws.attendance.domain.StuAttendance;
import com.sws.attendance.service.IStuAttendanceService;
import com.sws.common.utils.poi.ExcelUtil;
import com.sws.common.core.page.TableDataInfo;

/**
 * 学生签到记录Controller
 * 
 * @author cx
 * @date 2025-06-16
 */
@Api(tags = {"学生签到记录Controller"})
@RestController
@RequestMapping("/student/attendance/attendance")
public class StuAttendanceController extends BaseController
{
    @Autowired
    private IStuAttendanceService stuAttendanceService;

    @Autowired
    private IPerPersonService personService;

    @Autowired
    private CapRecordService capRecordService;
    /**
     * 查询学生签到记录列表
     */
    @ApiOperation("查询学生签到记录列表")
    @PreAuthorize("@ss.hasPermi('attendance:attendance:list')")
    @GetMapping("/list")
    public TableDataInfo list(StuAttendance stuAttendance)
    {
        startPage();
        List<StuAttendance> list = stuAttendanceService.selectStuAttendanceList(stuAttendance);
        return getDataTable(list);
    }

    /**
     * 导出学生签到记录列表
     */
    @ApiOperation("导出学生签到记录列表")
    @PreAuthorize("@ss.hasPermi('attendance:attendance:export')")
    @Log(title = "学生签到记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StuAttendance stuAttendance)
    {
        List<StuAttendance> list = stuAttendanceService.selectStuAttendanceList(stuAttendance);
        ExcelUtil<StuAttendance> util = new ExcelUtil<StuAttendance>(StuAttendance.class);
        util.exportExcel(response, list, "学生签到记录数据");
    }

    /**
     * 获取学生签到记录详细信息
     */
    @ApiOperation("获取学生签到记录详细信息")
    @PreAuthorize("@ss.hasPermi('attendance:attendance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stuAttendanceService.selectStuAttendanceById(id));
    }

    /**
     * 新增学生签到记录
     */
    @ApiOperation("新增学生签到记录")
    @PreAuthorize("@ss.hasPermi('attendance:attendance:add')")
    @Log(title = "学生签到记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StuAttendance stuAttendance)
    {
        StuAttendance sa = capRecordService.faceCaptureDevice(stuAttendance);
        return toAjax(stuAttendanceService.insertStuAttendance(sa));
    }

    /**
     * 修改学生签到记录
     */
    @ApiOperation("修改学生签到记录")
    @PreAuthorize("@ss.hasPermi('attendance:attendance:edit')")
    @Log(title = "学生签到记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StuAttendance stuAttendance)
    {

        return toAjax(stuAttendanceService.updateStuAttendance(stuAttendance));
    }

    /**
     * 删除学生签到记录
     */
    @ApiOperation("删除学生签到记录")
    @PreAuthorize("@ss.hasPermi('attendance:attendance:remove')")
    @Log(title = "学生签到记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stuAttendanceService.deleteStuAttendanceByIds(ids));
    }


}
